<template>
  <div class="form-wrap">
    <div class="clearfix title">
      <span class="h3">权限</span>
      {{ title }}
    </div>
    <keep-alive >
      <router-view
        :exportable="true"
        :table-title="tableTitle"
        :table-data="tableData"
        :defaultOperate="operable"
        :create-path="createPath"
        :creatable="false"
        :get-table-list="getTableList"
        :editable="true"
        :show-pagination="false"
        @childTitle="childTitle"
        @selectionChange="selectionChange"
        @del="del"
      />
    </keep-alive>
  </div>

</template>

<script>

export default {
  data() {
    return {
      title: '',
      operable: false,
      createPath: 'system_manage.jurisdiction.create',
      tableTitle: [
        {
          cn: 'id',
          en: 'id'
        },
        {
          cn: '标识',
          en: 'slug'
        },
        {
          cn: '名称',
          en: 'name'
        },
        {
          cn: '创建时间',
          en: 'created_at'
        },
        {
          cn: '更新时间',
          en: 'updated_at'
        }
      ],
      tableData: []
    }
  },
  methods: {
    getTableList(data) {
      const loading = this.$loading()
      this.$get('action/Permissions/dataGrid', data).then(res => {
        const list = res.data

        this.tableData = list || {}
        loading.close()
      })
        .catch(_=>{
          loading.close()
        })
    },

    selectionChange(val) {
      // console.log(val);
    },

    del(val) {
      if (val) {
        // 点单个删除
        this.$post('action/AdminMenu/del', { id: val.row.id })
          .then(res => {
            this.$message({
              message: res.msg,
              type: 'success'
            })
          })
      } else {
        // 点批量删除

      }
    },
    childTitle(val) {
      this.title = val
    },

    edit(val) {
      this.$router.push({
        name: 'system_manage.jurisdiction.edit',
        params: {
          data: val.row
        }
      })
    }
  }
}
</script>

<style scoped rel="stylesheet/scss" lang="scss">
    .form-wrap{
        padding:0 15px;
        .title{
            padding: 15px 0;
        }
    }
</style>
